package timein8;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.testng.annotations.Test;

public class MyTime {
    public static void main(String[] args) {

        zoneDateTime();

        timeZone();


    }

    @Test
    public void useInstant() {
        // 和时区无关，toString方法用格林尼治时间处理了
        Instant instant = Instant.now();
        System.out.println(" 标准时" + instant);


        Instant instant2 = Instant.ofEpochMilli(System.currentTimeMillis());
        Instant instant3 = Instant.ofEpochMilli(System.currentTimeMillis() + 1000 * 2);

        long second2 = instant2.getEpochSecond();
        long second3 = instant3.getEpochSecond();

        System.out.println(second2 +"\n" +second3);

        System.out.println("毫秒数" + instant2.toEpochMilli());

        Instant instant1 = Instant.ofEpochSecond(0);
        System.out.println(instant1);
    }


    public static void zoneDateTime() {
        // 本时区时间
        ZonedDateTime now = ZonedDateTime.now();
        System.out.println(now);
    }

    public static void timeZone() {
        LocalDate l = LocalDate.now(ZoneId.of("+08:00"));
        System.out.println(l);
        System.out.println(l.plusYears(1));
    }

    @Test
    public void t2() {
        System.out.println(System.currentTimeMillis());
    }



}
